]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/backlight: Fix keyboard backlight infinite loop
authorBarnabás Pőcze <pobrn@protonmail.com>
Wed, 3 Jan 2024 02:04:46 +0000 (03:04 +0100)
committerMarge Bot <marge-bot@gnome.org>
Tue, 16 Jan 2024 23:30:42 +0000 (23:30 +0000)
The logic could enter an infinite loop because it tried to
propagate local changes to g-s-d that were caused by signals sent
by g-s-d. For example:

  1. slider is set to 50
  2. Set(50) dbus call is sent
  3. slider is set to 51
  4. Set(51) dbus call is sent
  5. PropertiesChanged arrives due to Set(50)
  6. this._sliderItem.value is set to 50
  7. notify::value is emitted from this._sliderItem
  8. Set(50) dbus call is sent
  9. PropertiesChanged arrives due to Set(51)
 10. this._sliderItem.value is set to 51
 11. notify::value is emitted from this._sliderItem
 12. Set(51) dbus call is sent

To alleviate this issue, block signal handlers when the local state is
changed due to a remote event.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7111

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3086>

js/ui/status/backlight.js

index f3579184816b44aeccc03d882ce06437dfc33919..ca901d547869fd00be4ae0f02436e57e5f635b9e 100644 (file)
@@ -177,10 +177,10 @@ class KeyboardBrightnessToggle extends QuickMenuToggle {
             this._discreteItem, 'value',
             GObject.BindingFlags.SYNC_CREATE);
 
-        this._sliderItem.connect('notify::value',
+        this._sliderItemChangedId = this._sliderItem.connect('notify::value',
             () => (this._proxy.Brightness = this._sliderItem.value));
 
-        this._discreteItem.connect('notify::value',
+        this._discreteItemChangedId = this._discreteItem.connect('notify::value',
             () => (this._proxy.Brightness = this._discreteItem.value));
     }
 
@@ -194,6 +194,9 @@ class KeyboardBrightnessToggle extends QuickMenuToggle {
         this.checked = brightness > 0;
         const useSlider = this._proxy.Steps >= 4;
 
+        this._sliderItem.block_signal_handler(this._sliderItemChangedId);
+        this._discreteItem.block_signal_handler(this._discreteItemChangedId);
+
         this._sliderItem.set({
             visible: useSlider,
             value: brightness,
@@ -201,6 +204,9 @@ class KeyboardBrightnessToggle extends QuickMenuToggle {
 
         if (!useSlider)
             this._discreteItem.nLevels = this._proxy.Steps;
+
+        this._sliderItem.unblock_signal_handler(this._sliderItemChangedId);
+        this._discreteItem.unblock_signal_handler(this._discreteItemChangedId);
     }
 });